<?php

namespace app\admin\model\xykeep;

use think\Model;
use traits\model\SoftDelete;

class Goods extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'xykeep_goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'is_sku_text',
        'status_text'
    ];
    

    public function getDisRuleList()
    {
        return ['0' => __('默认规则'),'1' => __('单独设置')];

    }
    
    public function getDisRuleTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_sku']) ? $data['is_sku'] : '');
        $list = $this->getDisRuleList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getIsDisList()
    {
        return ['1' => __('参与'),'0' => __('不参与')];
    }
    
    public function getIsDisTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_sku']) ? $data['is_sku'] : '');
        $list = $this->getIsDisList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    

    public function getStatusList()
    {
        return ['up' => __('Status up'),  'down' => __('Status down')];
    }

    public function getIsSkuList()
    {
        return ['0' => __('单规格'), '1' => __('多规格')];
    }
    
    public function getIsSkuTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_sku']) ? $data['is_sku'] : '');
        $list = $this->getIsSkuList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function activity()
    {
        return $this->belongsTo('\app\admin\model\xykeep\goods\Activity', 'activity_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
